package com.example.foobar.controller;

import com.example.foobar.business.service.DaQrcodesService;
import com.example.foobar.entity.DaOfficialAccount;
import com.example.foobar.entity.DaQrcodes;
import com.example.foobar.dao.service.DaQrcodesDaoService;
import io.geekidea.springbootplus.framework.util.LoginUtil;
import lombok.extern.slf4j.Slf4j;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  控制器
 *
 * @author 郑英奔
 * @since 2021-07-15
 */
@Slf4j
@RestController
@RequestMapping("/daQrcodes")
@Module("foobar")
@Api(value = "API", tags = {""})
public class DaQrcodesController extends BaseController {

    @Autowired
    private DaQrcodesService daQrcodesService;

    /**
     * 添加
     */
    @PostMapping("/add")
    @OperationLog(name = "添加", type = OperationLogType.ADD)
    @ApiOperation(value = "添加", response = ApiResult.class)
    public ApiResult<Boolean> addDaQrcodes(@Validated(Add.class) @RequestBody DaQrcodes daQrcodes) throws Exception {
        boolean flag = daQrcodesService.saveDaQrcodes(daQrcodes);
        return ApiResult.result(flag);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @OperationLog(name = "修改", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改", response = ApiResult.class)
    public ApiResult<Boolean> updateDaQrcodes(@Validated(Update.class) @RequestBody DaQrcodes daQrcodes) throws Exception {
        boolean flag = daQrcodesService.updateDaQrcodes(daQrcodes);
        return ApiResult.result(flag);
    }

    /**
     * 删除
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除", response = ApiResult.class)
    public ApiResult<Boolean> deleteDaQrcodes(@PathVariable("id") Long id) throws Exception {
        boolean flag = daQrcodesService.deleteDaQrcodes(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "详情", type = OperationLogType.INFO)
    @ApiOperation(value = "详情", response = DaQrcodes.class)
    public ApiResult<DaQrcodes> getDaQrcodes(@PathVariable("id") Long id) throws Exception {
        DaQrcodes daQrcodes = daQrcodesService.getById(id);
        return ApiResult.ok(daQrcodes);
    }

    @PostMapping("/getList")
    @RequiresPermissions("sys:qr-rate:page")
    @OperationLog(name = "获取二维码列表", type = OperationLogType.LIST)
    @ApiOperation(value = "获取二维码列表", response = DaOfficialAccount.class)
    public ApiResult<List<DaQrcodes>> getRoleList() {

        return ApiResult.ok(daQrcodesService.list());
    }
}

